package thinkingJava.chapter10;
interface Game {
	boolean move();
}
interface GameFactory {
	Game getGame();
}
class Checkers implements Game {
	private Checkers() {
	}
	private int moves = 0;
	private static final int MOVE = 3;

	public boolean move() {
		System.out.println("checkers move " + moves);
		return ++moves != MOVE;
	}
	public static GameFactory factory =
		new GameFactory(){
		public Game getGame() {
			return new Checkers();
		}
	};
}
class Chess implements Game {
	private int moves = 0;
	private static final int MOVES = 4;
	private Chess() {}
	public boolean move() {
		System.out.println("chess move " + moves);
		return ++moves != MOVES;
	}
	public static GameFactory factory =
		new GameFactory() {
			public Game getGame() {
				return new Chess();
			}
	};
}
public class Games {
	public static void playGame(GameFactory factory) {
		Game g = factory.getGame();
		while (g.move()) {
			;
		}
	}
	public static void main(String[] args) {
		playGame(Checkers.factory);
		playGame(Chess.factory);
	}
}
